﻿using System;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using PMS.BLL;
using PMS.Entity;
using PMS.Resources;
using PMS.Win;
using PMS.Utils;
using DevExpress.XtraEditors.Mask;
using PMS.DanhMucChung;
using System.Collections.Generic;
using PMS.ValidationRules;
using PMS.ReportViewer;

namespace PMS.ChucNang
{
    public partial class TheKhoByDate : FormManualBase
    {
        public TheKhoByDate()
        {
            InitializeComponent();
        }

        public TheKhoByDate(String functionID)
            : base(functionID)
        {
            InitializeComponent();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btneMaThuoc_Click(object sender, EventArgs e)
        {
            try
            {
                ProductLookup form = new ProductLookup();
                if (form.ShowDialog() == DialogResult.OK)
                {
                    if (form.ProductSelected != null)
                    {
                        btneMaThuoc.EditValue = form.ProductSelected.MaThuoc;
                    }
                }
            }
            catch (Exception ex)
            {
                ShowErrorMessage(ex);
            }
        }

        private void btneSoLo_Click(object sender, EventArgs e)
        {
            try
            {
                LuuKhoLookup form = new LuuKhoLookup(null, DataConvertUltils.ToString(btneMaThuoc.EditValue), null, null);
                if (form.ShowDialog() == DialogResult.OK)
                {
                    if (form.LuuKhoSelected != null)
                    {
                        btneSoLo.EditValue = form.LuuKhoSelected.SoLo;
                    }
                }
            }
            catch (Exception ex)
            {
                ShowErrorMessage(ex);
            }
        }

        private void btnXem_Click(object sender, EventArgs e)
        {
            try
            {
                if (ValidateControls())
                {
                    String MaThuoc = DataConvertUltils.ToString(btneMaThuoc.EditValue);
                    String SoLo = DataConvertUltils.ToString(btneSoLo.EditValue);
                    XtraForm form = new BaseForm();
                    form = new TheKhoByDateViewer(MaThuoc, SoLo, (DateTime?)dateTuNgay.EditValue, (DateTime?)dateDenNgay.EditValue);
                    
                    form.WindowState = FormWindowState.Maximized;
                    form.StartPosition = FormStartPosition.CenterParent;
                    form.ShowDialog();
                }
            }
            catch (Exception ex)
            {
                ShowErrorMessage(ex);
            }
        }
    }
}